/*   1:    */ package org.intellij.plugins.relaxNG.convert;
/*   2:    */ 
/*   3:    */

import com.intellij.icons.AllIcons.General;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiRecursiveElementVisitor;
import com.intellij.psi.xml.XmlAttributeDecl;
import com.intellij.psi.xml.XmlElementDecl;
import org.jetbrains.annotations.NonNls;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */ 
/*  41:    */ public class AdvancedDtdOptions
/*  42:    */   implements AdvancedOptions
/*  43:    */ {
/*  44:    */   @NonNls
/*  45:    */   private static final String a = "colon-replacement";
/*  46:    */   @NonNls
/*  47:    */   private static final String b = "element-define";
/*  48:    */   @NonNls
/*  49:    */   private static final String c = "attlist-define";
/*  50:    */   @NonNls
/*  51:    */   private static final String d = "inline-attlist";
/*  52:    */   @NonNls
/*  53:    */   private static final String e = "any-name";
/*  54:    */   @NonNls
/*  55:    */   private static final String f = "strict-any";
/*  56:    */   @NonNls
/*  57:    */   private static final String g = "annotation-prefix";
/*  58:    */   @NonNls
/*  59:    */   private static final String h = "generate-start";
/*  60:    */   @NonNls
/*  61:    */   private static final String i = "xmlns";
/*  62:    */   private JComponent j;
/*  63:    */   private JCheckBox k;
/*  64:    */   private JTextField l;
/*  65:    */   private JTextField m;
/*  66:    */   private JTextField n;
/*  67:    */   private JTextField o;
/*  68:    */   private JCheckBox p;
/*  69:    */   private JTextField q;
/*  70:    */   private JCheckBox r;
/*  71:    */   private JTextField s;
/*  72:    */   private JTable t;
/*  73:    */   private JPanel u;
/*  74:    */   
/*  75:    */   public AdvancedDtdOptions()
/*  76:    */   {
/*  77: 78 */     a();this.k.addItemListener(new ItemListener()
/*  78:    */     {
/*  79:    */       public void itemStateChanged(ItemEvent paramAnonymousItemEvent)
/*  80:    */       {
/*  81: 80 */         if (paramAnonymousItemEvent.getStateChange() == 1) {
/*  82: 81 */           AdvancedDtdOptions.this.n.setEnabled(false);
/*  83:    */         } else {
/*  84: 83 */           AdvancedDtdOptions.this.n.setEnabled(true);
/*  85:    */         }
/*  86:    */       }
/*  87: 86 */     });
/*  88: 87 */     this.t.setModel(new NamespaceMapModel(null));
/*  89: 88 */     this.t.getColumnModel().getColumn(0).setMaxWidth((int)(new JLabel("Prefix").getPreferredSize().width * 1.2D));
/*  90:    */     
/*  91: 90 */     DefaultActionGroup localDefaultActionGroup = new DefaultActionGroup();
/*  92: 91 */     localDefaultActionGroup.add(new AnAction(null, "Remove Entry", AllIcons.General.Remove)
/*  93:    */     {
/*  94:    */       public void update(AnActionEvent paramAnonymousAnActionEvent)
/*  95:    */       {
/*  96: 93 */         if ((AdvancedDtdOptions.this.t.getModel().getRowCount() == 0) || (AdvancedDtdOptions.this.t.getSelectedRow() == -1)) {
/*  97: 94 */           paramAnonymousAnActionEvent.getPresentation().setEnabled(false);
/*  98:    */         } else {
/*  99: 96 */           paramAnonymousAnActionEvent.getPresentation().setEnabled(true);
/* 100:    */         }
/* 101:    */       }
/* 102:    */       
/* 103:    */       public void actionPerformed(AnActionEvent paramAnonymousAnActionEvent)
/* 104:    */       {
/* 105:101 */         ((AdvancedDtdOptions.NamespaceMapModel)AdvancedDtdOptions.this.t.getModel()).removeRow(AdvancedDtdOptions.this.t.getSelectedRow());
/* 106:    */       }
/* 107:104 */     });
/* 108:105 */     ActionToolbar localActionToolbar = ActionManager.getInstance().createActionToolbar("unknown", localDefaultActionGroup, false);
/* 109:106 */     this.u.add(localActionToolbar.getComponent());
/* 110:    */   }
/* 111:    */   
/* 112:    */   public JComponent getRoot()
/* 113:    */   {
/* 114:110 */     return this.j;
/* 115:    */   }
/* 116:    */   
/* 117:    */   public Map<String, ?> getOptions()
/* 118:    */   {
/* 119:114 */     LinkedHashMap localLinkedHashMap = new LinkedHashMap();
/* 120:    */     
/* 121:116 */     localLinkedHashMap.put("inline-attlist", Boolean.valueOf(this.k.isSelected()));
/* 122:    */     
/* 123:118 */     a(localLinkedHashMap, "colon-replacement", this.l);
/* 124:119 */     a(localLinkedHashMap, "element-define", this.m);
/* 125:120 */     a(localLinkedHashMap, "attlist-define", this.n);
/* 126:121 */     a(localLinkedHashMap, "any-name", this.o);
/* 127:123 */     if (this.p.isSelected()) {
/* 128:124 */       localLinkedHashMap.put("strict-any", Boolean.TRUE);
/* 129:    */     }
/* 130:127 */     a(localLinkedHashMap, "annotation-prefix", this.q);
/* 131:    */     
/* 132:129 */     localLinkedHashMap.put("generate-start", Boolean.valueOf(this.r.isSelected()));
/* 133:131 */     if (this.s.getText().trim().length() > 0) {
/* 134:132 */       localLinkedHashMap.put("xmlns", this.s.getText());
/* 135:    */     }
/* 136:135 */     List localList = ((NamespaceMapModel)this.t.getModel()).getData();
/* 137:136 */     for (String[] arrayOfString : localList) {
/* 138:137 */       localLinkedHashMap.put("xmlns:" + arrayOfString[0], arrayOfString[1]);
/* 139:    */     }
/* 140:140 */     return localLinkedHashMap;
/* 141:    */   }
/* 142:    */   
/* 143:    */   private static void a(HashMap<String, Object> paramHashMap, String paramString, JTextField paramJTextField)
/* 144:    */   {
/* 145:144 */     String str = paramJTextField.getText();
/* 146:145 */     if ((str != null) && (str.trim().length() > 0)) {
/* 147:146 */       paramHashMap.put(paramString, str);
/* 148:    */     }
/* 149:    */   }
/* 150:    */   
/* 151:    */   public void setOptions(Map<String, ?> paramMap)
/* 152:    */   {
/* 153:151 */     if (paramMap.containsKey("colon-replacement")) {
/* 154:152 */       this.l.setText((String)paramMap.get("colon-replacement"));
/* 155:    */     }
/* 156:154 */     this.k.setSelected(paramMap.get("inline-attlist") == Boolean.TRUE);
/* 157:156 */     if (paramMap.containsKey("element-define")) {
/* 158:157 */       this.m.setText((String)paramMap.get("element-define"));
/* 159:    */     }
/* 160:159 */     if (paramMap.containsKey("attlist-define")) {
/* 161:160 */       this.n.setText((String)paramMap.get("attlist-define"));
/* 162:    */     }
/* 163:162 */     if (paramMap.containsKey("any-name")) {
/* 164:163 */       this.o.setText((String)paramMap.get("any-name"));
/* 165:    */     }
/* 166:165 */     this.p.setSelected(paramMap.get("strict-any") == Boolean.TRUE);
/* 167:166 */     if (paramMap.containsKey("annotation-prefix")) {
/* 168:167 */       this.q.setText((String)paramMap.get("annotation-prefix"));
/* 169:    */     }
/* 170:169 */     this.r.setSelected(paramMap.get("generate-start") == Boolean.TRUE);
/* 171:170 */     if (paramMap.containsKey("xmlns")) {
/* 172:171 */       this.s.setText((String)paramMap.get("xmlns"));
/* 173:    */     }
/* 174:174 */     NamespaceMapModel localNamespaceMapModel = (NamespaceMapModel)this.t.getModel();
/* 175:175 */     Set localSet = paramMap.keySet();
/* 176:176 */     String str1 = "xmlns:";
/* 177:177 */     for (String str2 : localSet) {
/* 178:178 */       if (str2.startsWith("xmlns:")) {
/* 179:179 */         localNamespaceMapModel.addMapping(str2.substring("xmlns:".length()), (String)paramMap.get(str2));
/* 180:    */       }
/* 181:    */     }
/* 182:    */   }
/* 183:    */   
/* 184:    */   public static Map<String, ?> prepareNamespaceMap(Project paramProject, VirtualFile paramVirtualFile)
/* 185:    */   {
/* 186:185 */     PsiFile localPsiFile = PsiManager.getInstance(paramProject).findFile(paramVirtualFile);
/* 187:186 */     if (localPsiFile == null) {
/* 188:187 */       return Collections.emptyMap();
/* 189:    */     }
/* 190:190 */     LinkedHashMap localLinkedHashMap = new LinkedHashMap();
/* 191:191 */     localPsiFile.accept(new PsiRecursiveElementVisitor()
/* 192:    */     {
/* 193:    */       public void visitElement(PsiElement paramAnonymousPsiElement)
/* 194:    */       {
/* 195:    */         String str;
/* 196:    */         String[] arrayOfString;
/* 197:193 */         if ((paramAnonymousPsiElement instanceof XmlElementDecl))
/* 198:    */         {
/* 199:194 */           str = ((XmlElementDecl)paramAnonymousPsiElement).getName();
/* 200:195 */           if (str != null)
/* 201:    */           {
/* 202:196 */             arrayOfString = str.split(":");
/* 203:197 */             if (arrayOfString.length > 1) {
/* 204:198 */               this.val$map.put("xmlns:" + arrayOfString[0], null);
/* 205:    */             }
/* 206:    */           }
/* 207:    */         }
/* 208:201 */         else if ((paramAnonymousPsiElement instanceof XmlAttributeDecl))
/* 209:    */         {
/* 210:202 */           str = ((XmlAttributeDecl)paramAnonymousPsiElement).getName();
/* 211:203 */           if (str != null)
/* 212:    */           {
/* 213:204 */             arrayOfString = str.split(":");
/* 214:205 */             if (arrayOfString.length > 1) {
/* 215:206 */               this.val$map.put("xmlns:" + arrayOfString[0], null);
/* 216:    */             }
/* 217:    */           }
/* 218:    */         }
/* 219:210 */         super.visitElement(paramAnonymousPsiElement);
/* 220:    */       }
/* 221:213 */     });
/* 222:214 */     return localLinkedHashMap;
/* 223:    */   }
/* 224:    */   
/* 225:    */   private static class NamespaceMapModel
/* 226:    */     extends AbstractTableModel
/* 227:    */   {
/* 228:218 */     private final List<String[]> a = new ArrayList();
/* 229:    */     
/* 230:    */     public String getColumnName(int paramInt)
/* 231:    */     {
/* 232:221 */       return paramInt == 0 ? "Prefix" : "URI";
/* 233:    */     }
/* 234:    */     
/* 235:    */     public int getRowCount()
/* 236:    */     {
/* 237:225 */       return this.a.size();
/* 238:    */     }
/* 239:    */     
/* 240:    */     public int getColumnCount()
/* 241:    */     {
/* 242:229 */       return 2;
/* 243:    */     }
/* 244:    */     
/* 245:    */     public boolean isCellEditable(int paramInt1, int paramInt2)
/* 246:    */     {
/* 247:233 */       return paramInt2 == 1;
/* 248:    */     }
/* 249:    */     
/* 250:    */     public void setValueAt(Object paramObject, int paramInt1, int paramInt2)
/* 251:    */     {
/* 252:237 */       ((String[])this.a.get(paramInt1))[paramInt2] = ((String)paramObject);
/* 253:    */     }
/* 254:    */     
/* 255:    */     public Object getValueAt(int paramInt1, int paramInt2)
/* 256:    */     {
/* 257:241 */       return ((String[])this.a.get(paramInt1))[paramInt2];
/* 258:    */     }
/* 259:    */     
/* 260:    */     public void addMapping(String paramString1, String paramString2)
/* 261:    */     {
/* 262:245 */       this.a.add(new String[] { paramString1, paramString2 });
/* 263:246 */       fireTableRowsInserted(this.a.size() - 1, this.a.size() - 1);
/* 264:    */     }
/* 265:    */     
/* 266:    */     public void removeRow(int paramInt)
/* 267:    */     {
/* 268:250 */       this.a.remove(paramInt);
/* 269:251 */       fireTableRowsDeleted(paramInt - 1, paramInt - 1);
/* 270:    */     }
/* 271:    */     
/* 272:    */     public List<String[]> getData()
/* 273:    */     {
/* 274:255 */       return this.a;
/* 275:    */     }
/* 276:    */   }
/* 277:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.convert.AdvancedDtdOptions

 * JD-Core Version:    0.7.0.1

 */